package com.itheima.day11.charstream.test9;

import java.io.*;
import java.util.ArrayList;
import java.util.Arrays;

public class Test {
    public static void main(String[] args) throws IOException {
        // 创建字符输缓冲入流
        BufferedReader br = new BufferedReader(new FileReader("myCode\\src\\com\\itheima\\day11\\d.txt"));

        // 获得文件中的数据
        String line;
        ArrayList<String> al = new ArrayList<>();
        while ((line = br.readLine()) != null) {
            al.add(line);
        }

        // 排序
        for (int i = 0; i < al.size(); i++) {
            String str = al.get(i);
            str.trim();
            String[] split = str.split(" ");
            Arrays.sort(split);
            String str2 = "";
            for (int j = 0; j < split.length; j++) {
                if (j == split.length - 1) {
                    str2 += split[j];
                } else {
                    str2 += split[j] + " ";
                }
            }
            al.set(i, str2);
        }

        // 赋值
        BufferedWriter bw = new BufferedWriter(new FileWriter("myCode\\src\\com\\itheima\\day11\\e.txt"));
        for (String s : al) {
            bw.write(s);
            bw.newLine();
        }

        br.close();
        bw.close();

    }
}
